﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Mail;


namespace INSTA.MusiqueStore.DAL
{
   public   class SendPassword
   {
       public static string email;
       public static void sendmail(string  Email)
       {
            email = Email;
           string paswd;
           var c = new MusiqueStoreEntities();
           var a = (from Client in c.Clients
                    where Client.Email == email 
                    select Client.Password).ToList();

           foreach (var pwd in c.Clients )
           {
                paswd = pwd.Password;
           

           //Envoi du mail
           MailMessage message = new MailMessage();
           message .From=new System.Net.Mail.MailAddress("christelmiss@gmail.com");
           message .To.Add(new MailAddress(email));
          message .IsBodyHtml = true; 
           message .Subject = "MusiqueStore: Votre mot de passe";
           message .Body = "  Votre mot de passe :"+paswd+"";
           System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
           smtp.Host = "smtp.gmail.com";
           smtp.Port = 465;
           smtp.EnableSsl = true;

           smtp.Credentials = new System.Net.NetworkCredential("source", "mot de passe");
           try
           {
               
               smtp.Send(message );
              // MessageBox.Show("email est envoyer");
           }
           catch (SmtpException ex)
           {
               Console.WriteLine(
            "Exception caught in CreateTestMessage1(): {0}",
            ex.ToString());

               
           } 
              

}

           }

       }

    }

